package com.cdty.chess.controller;

import com.cdty.chess.model.Cuser;
import com.cdty.chess.service.CuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/cuser")
public class CuserController {


    @Autowired
    CuserService service;

    @PostMapping("/addCuser")
    public String addCuser(@RequestBody Cuser cuser) {
        return service.addCuser(cuser);
    }


    @PostMapping("/changePass")
    public String changePass(@RequestBody Cuser cuser) {
        return service.changePass(cuser);
    }



    /**
     * 更新
     * @param cuser
     * @return
     */
    @PostMapping("/updateCuser")
    public String updateCuser(@RequestBody Cuser cuser) {
        String message = service.updateCuser(cuser);
        return message;
    }

    /**
     * 更新admin总余额
     * @param cuser
     * @return
     */
    @PostMapping("/updateAdmin")
    public String updateAdmin(@RequestParam BigDecimal score) {
        String message = service.updateAdmin(score);
        return message;
    }

    /**
     * 查询
     * @param cuser
     * @return
     */
    @PostMapping("/getCuser")
    public List<Cuser> getCuser(@RequestBody Cuser cuser) {
        List<Cuser> userList = service.getCuser(cuser);
        return userList;
    }


    /**
     * 查询
     * @param name 搜素名字
     * @return
     */
    @GetMapping("/getCuserPage")
    public Map<String,Object> getCuserPage(@RequestParam(required = false) String uname,
                                           @RequestParam(required = false) Integer page,
                                           @RequestParam(required = false) Integer size) {
        return  service.getCuserPage(uname,page,size);
    }
}
